//
//  DownloadTool.m
//  Douban Two
//
//  Created by dlios on 15/3/2.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DownloadTool.h"

@implementation DownloadTool

- (instancetype)initWithUrlStr:(NSString *)urlStr
{
    self = [super init];
    if (self) {
        [self downloadData:urlStr];
    }
    return self;
}

- (void)downloadData:(NSString *)urlStr
{
    NSString *urlStrEncode = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
    [manager GET:urlStrEncode parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        [netWorkManager stopMonitoring];
        [self.myDelegate didDownloadFinished:responseObject];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"请求失败, error = %@", error);
        [self.myDelegate downloadError:error];
    }];
    
    
    
}



@end
